/**
 * @author Jason Pratt
 */

package edu.cmu.cs.stage3.alice.authoringtool;

import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;

import edu.cmu.cs.stage3.alice.authoringtool.event.AuthoringToolStateChangedEvent;
import edu.cmu.cs.stage3.alice.authoringtool.event.AuthoringToolStateListener;
import edu.cmu.cs.stage3.util.HowMuch;

public class StatusBar extends javax.swing.JPanel implements AuthoringToolStateListener {

 public StatusBar( AuthoringTool authoringTool ) {
  jbInit();
  authoringTool.addAuthoringToolStateListener( this );
 }

 ///////////////////////////////////////////////
 // AuthoringToolStateListener interface
 ///////////////////////////////////////////////

 public void worldLoaded( AuthoringToolStateChangedEvent ev ) {
  updateWorldStats( ev.getWorld() );
 }

 public void worldUnLoaded( AuthoringToolStateChangedEvent ev ) {
  updateWorldStats( null );
 }

 public void stateChanging( AuthoringToolStateChangedEvent ev ) {}
 public void worldLoading( AuthoringToolStateChangedEvent ev ) {}
 public void worldUnLoading( AuthoringToolStateChangedEvent ev ) {}
 public void worldStarting( AuthoringToolStateChangedEvent ev ) {}
 public void worldStopping( AuthoringToolStateChangedEvent ev ) {}
 public void worldPausing( AuthoringToolStateChangedEvent ev ) {}
 public void worldSaving( AuthoringToolStateChangedEvent ev ) {}
 public void stateChanged( AuthoringToolStateChangedEvent ev ) {}
 public void worldStarted( AuthoringToolStateChangedEvent ev ) {}
 public void worldStopped( AuthoringToolStateChangedEvent ev ) {}
 public void worldPaused( AuthoringToolStateChangedEvent ev ) {}
 public void worldSaved( AuthoringToolStateChangedEvent ev ) {}

 private void updateWorldStats( edu.cmu.cs.stage3.alice.core.World world ) {

  if( world != null ) {
   edu.cmu.cs.stage3.alice.core.util.IndexedTriangleArrayCounter itaCounter = new edu.cmu.cs.stage3.alice.core.util.IndexedTriangleArrayCounter();

   world.visit( itaCounter, HowMuch.INSTANCE_AND_ALL_DESCENDANTS );


  } else {
   objectCountLabel.setText( "object count: 0"  );
   faceCountLabel.setText( "face count: 0"  );
  }
 }

 //////////////////
 // Autogenerated
 //////////////////

 Border border1;
 GridBagLayout gridBagLayout1 = new GridBagLayout();
 JPanel worldStatsPanel = new JPanel();
 JLabel worldStatsLabel = new JLabel();
 GridBagLayout gridBagLayout2 = new GridBagLayout();
 JLabel objectCountLabel = new JLabel();
 JLabel faceCountLabel = new JLabel();
 Component filler1;
 Border border2;

 private void jbInit() {
  border1 = BorderFactory.createEmptyBorder(1,1,1,1);
  filler1 = Box.createGlue();
  border2 = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(142, 142, 142),new Color(99, 99, 99));
  this.setBackground(new Color(204, 204, 204));
  this.setBorder(border1);
  this.setLayout(gridBagLayout1);
  worldStatsLabel.setText("Statistics:");
  worldStatsPanel.setLayout(gridBagLayout2);
  objectCountLabel.setBackground(new Color(0, 204, 0));
  objectCountLabel.setForeground(Color.black);
  objectCountLabel.setOpaque(true);
  objectCountLabel.setHorizontalAlignment(SwingConstants.CENTER);
  objectCountLabel.setHorizontalTextPosition(SwingConstants.CENTER);
  objectCountLabel.setText("object count:");
  faceCountLabel.setBackground(new Color(0, 204, 0));
  faceCountLabel.setForeground(Color.black);
  faceCountLabel.setOpaque(true);
  faceCountLabel.setHorizontalAlignment(SwingConstants.CENTER);
  faceCountLabel.setHorizontalTextPosition(SwingConstants.CENTER);
  faceCountLabel.setText("face count:");
  worldStatsPanel.setBorder(border2);
  this.add(worldStatsPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 4));
  worldStatsPanel.add(worldStatsLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 6), 0, 0));
  worldStatsPanel.add(objectCountLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 10, 0));
  worldStatsPanel.add(faceCountLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 6), 10, 0));
  worldStatsPanel.add(filler1, new GridBagConstraints(4, 0, 1, 1, 1.0, 0.0
    ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
 }

}
